package com.roncoo.eshop.inventory.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.roncoo.eshop.inventory.dao.RedisDAO;
import com.roncoo.eshop.inventory.mapper.UserMapper;
import com.roncoo.eshop.inventory.model.User;
import com.roncoo.eshop.inventory.service.UserService;

/**
 * Copyright: Copyright (c) 2019 Hu-Cheng
 * 
 * @ClassName: UserServiceImpl.java
 * @Description: 用户业务层实现类
 *
 * @version: v1.0.0
 * @author: hucheng
 * @date: 2019年9月18日 下午5:14:55
 *
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private RedisDAO redisDAO;

	@Autowired
	private UserMapper userMapper;

	@Override
	public User getUserInfo() {
		return userMapper.findUser();
	}

	@Override
	public User getCacheUserInfo() {

		JSONObject jsonObject = new JSONObject();
		jsonObject.put("name", "zhangsan");
		jsonObject.put("age", "100");
		redisDAO.set("cache_user", jsonObject.toJSONString());

		String jsonString = redisDAO.get("cache_user");
		User user = JSONObject.parseObject(jsonString, User.class);
		return user;
	}

}
